<template>
  <el-header>
    <div class="l-content">
      <!-- 图标的展示 -->
      <el-button size="small" @click="changeCollapse()">
        <el-icon :size="20"><Menu /></el-icon>
      </el-button>
      <h3>
        <el-breadcrumb separator="/" class="bread">
          <el-breadcrumb-item :to="current.path" v-if="current">{{
            current.label
          }}</el-breadcrumb-item>
        </el-breadcrumb>
      </h3>
    </div>
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <span class="username">{{ userStore.name }}</span>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="() => {$router.push('/homePage')}">个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleExit">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script setup>
import { getCurrentInstance, ref, onMounted } from 'vue';
import { userInfoStore,collapseStore } from '@/store';

const userStore = userInfoStore();
const _this = getCurrentInstance().appContext.config.globalProperties;
 
const handleExit = ()=> {
  window.localStorage.removeItem("token");
  let clearUser = {
    userId: 0,
    username: 'username',
    name:'name',
    authority: 3,
    password: 'password',
    remarks: 'remarks',
    authorityName: 'authorityName'
  }
  userStore.setAll(clearUser);
  _this.$router.push('/login');
}


const changeCollapse = ()=> {
  let collapse = collapseStore();
  collapse.setCollapse(!collapse.collapse);
}

</script>

<style lang="less" scoped>
.username{
  color: #ffffff;
  font-size: 20px;
  padding-right: 30px;
  letter-spacing: 2px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: #495057;
}
.r-content {
  .user {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
.l-content {
  display: flex;
  align-items: center;
  .el-button {
    margin-right: 20px;
  }
  h3 {
    color: #fff;
  }
}
:deep(.bread span) {
  color: #fff !important;
  cursor: pointer !important;
}
</style>